package com.itheima.sevrice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.DishFlavor;
import com.itheima.dao.DishFlavorDao;
import com.itheima.sevrice.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DishFlavorServiceImpl  implements DishFlavorService {

    @Autowired(required = false)
    private DishFlavorDao dishFlavorDao;

    /**
     * 添加口味
     *
     * @param dishFlavor
     * @return
     */
    @Override
    public int addDishFlavor(DishFlavor dishFlavor) {
        return dishFlavorDao.insert(dishFlavor);
    }

    /**
     * 根据菜品ID 指定删除绑定的口味数据
     *
     * @param dishIds
     * @return
     */
    @Override
    public int deleteDishFlavor(List<Long> dishIds) {
        return dishFlavorDao.deleteBatchIds(dishIds);
    }

    /**
     * 根据菜品Id 查找绑定的口味数据
     *
     * @param dishId
     * @return
     */
    @Override
    public List<DishFlavor> findByDishId(Long dishId) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,dishId);
        return dishFlavorDao.selectList(lqw);
    }

    /**
     * 根据菜品的id 删除口味数据
     *
     * @param dishId
     * @return
     */
    @Override
    public int deleteDishIdFlavor(Long dishId) {
        //构建条件对象
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,dishId);
        return dishFlavorDao.delete(lqw);
    }
}
